import { _decorator, Component, Node ,screen} from 'cc';
import { Scene } from './Scene';
const { ccclass, property } = _decorator;

@ccclass('Guide')
export class Guide extends Component {

    @property(Scene)
    public scene:Scene
    
    private noclickTimer:number;

    @property(Node)
    public guideHand:Node;

    start() {
        this.noclickTimer = 0;
        this.guideHand.active = false;

        this.scene.eventTarget.on("upgradeAny",(event)=>{
            this.noclickTimer = 0;
            this.guideHand.active = false;
        });
    }

    update(deltaTime: number) {
        var btnList = this.scene.btnListSP;
        if(screen.windowSize.width > screen.windowSize.height){
            btnList = this.scene.btnListHP;
        }


        if(btnList[0].node.children[0].active){
            this.noclickTimer += deltaTime;   
            if(this.noclickTimer >= 1){

                if(btnList[2].node.children[0].active){
                    this.guideHand.active = true;
                    this.guideHand.worldPosition = btnList[2].node.worldPosition;
                    return;
                }

                if(btnList[1].node.children[0].active){
                    this.guideHand.active = true;
                    this.guideHand.worldPosition = btnList[1].node.worldPosition;
                    return;
                }

                if(btnList[0].node.children[0].active){
                    this.guideHand.active = true;
                    this.guideHand.worldPosition = btnList[0].node.worldPosition;
                    return;
                }

            }
        }
    }
}


